//
//  BaseViewController.m
//  舟航007机车卫士
//
//  Created by admin on 15/11/9.
//  Copyright (c) 2015年 redoor. All rights reserved.
//

#import "RegisterBaseViewController.h"
#import "AFNetworking.h"

@interface RegisterBaseViewController ()

@end

@implementation RegisterBaseViewController
@synthesize leftbtn,rightlab,titletext;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor colorWithRed:(CGFloat)45/255 green:(CGFloat)143/255 blue:(CGFloat)247/255 alpha:1.0];
    titletext=[[UILabel alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-180*W)/2,20+10*H, 180*W, 20*H)];
    titletext.textColor=[UIColor whiteColor];
    titletext.textAlignment=NSTextAlignmentCenter;
    titletext.text=@"22222";
    leftbtn=[[CustomButton alloc]initWithFrame:CGRectMake(10*W,20+5*H,100*W, 30*H)];
    leftbtn.titleLabel.font=[UIFont systemFontOfSize:13];
    [leftbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [leftbtn setTitle:@"首页" forState:UIControlStateNormal];
    [leftbtn setImage:[UIImage imageNamed:@"3pic_home"] forState:UIControlStateNormal];
    [leftbtn addTarget:self action:@selector(tapped_returnhome) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftbtn];
    [self.view addSubview:titletext];
}
- (void)tapped_returnhome{
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"yiwan_confirmpwd"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"yiwan_pwd"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"phoneNo"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"verifyCode"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"idcardNum"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"personName"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"provinceName"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"cityName"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"districtName"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"detailAdd"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"simId"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"brandName"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"buyTime"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"frameId"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"password"];
    
    NSFileManager * fileManager = [NSFileManager defaultManager];
    NSString *idCardPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"idcardPic.png"];
    [fileManager removeItemAtPath:idCardPath error:nil];
    
    NSString *ebicyclePath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"ebicyclePic.png"];
    [fileManager removeItemAtPath:ebicyclePath error:nil];
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)addTitle:(NSString *)titleName
{
    titletext.text = titleName;
}

- (void)enableButton:(UIButton *)btn
{
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.enabled = YES;
}

- (void)disableButton:(UIButton *)btn
{
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.enabled = NO;
}

- (UILabel *)createLabelFrame:(CGRect)frame title:(NSString *)title font:(UIFont *)font
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    if (title) {
        label.text = title;
    }
    if (font) {
        label.font = font;
    }
    label.textAlignment = NSTextAlignmentCenter;
    label.numberOfLines = 1;
    label.textColor = [UIColor whiteColor];
    return label;
}

- (UITextField *)createTextFieldFrame:(CGRect)frame title:(NSString *)title placeholder:(NSString *)placeholder
{
    UITextField *field = [[UITextField alloc] initWithFrame:frame];
    if (title) {
        field.text = title;
    }
    if (placeholder) {
        field.placeholder = placeholder;
    }
    field.borderStyle = UITextBorderStyleRoundedRect;
    field.textAlignment = NSTextAlignmentCenter;
    field.font = [UIFont systemFontOfSize:17];
    return field;
}

- (UIButton *)createBtnFrame:(CGRect)frame title:(NSString *)title bgImageName:(NSString *)bgImageName selectedImageName:(NSString *)selectedImageName target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    if (title) {
        [btn setTitle:title forState:UIControlStateNormal];
    }
    if (target && action) {
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    if (bgImageName) {
        [btn setBackgroundImage:[UIImage imageNamed:bgImageName] forState:UIControlStateNormal];
    }
    if (selectedImageName) {
        [btn setBackgroundImage:[UIImage imageNamed:selectedImageName] forState:UIControlStateHighlighted];
    }
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    return btn;
}

- (UIButton *)addLastBtnTarget:(id)target action:(SEL)action
{
    UIButton *btn = [self createBtnFrame:CGRectMake(40*W, SCREEN_HEIGHT-80*H, 60*W, 30*H) title:@"上一步" bgImageName:nil selectedImageName:nil target:target action:action];
    btn.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:btn];
    return btn;
}

- (UIButton *)addNextBtnTarget:(id)target action:(SEL)action
{
    UIButton *btn = [self createBtnFrame:CGRectMake(SCREEN_WIDTH-100*W, SCREEN_HEIGHT-80*H, 60*W, 30*H) title:@"下一步" bgImageName:nil selectedImageName:nil target:target action:action];
    btn.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:btn];
    return btn;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
